;
(function($)
{
    
    function RandomString(legalCharList)
    {
        var defaultLegalChar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        if(legalCharList === undefined)
        {
            this._legalCharList = defaultLegalChar.split("");
        }
        else
        {
            this._legalCharList = legalCharList.split("");
        }
    }

    RandomString.prototype = {
        
        getRandomStr : function(length)
        {
            if(length === undefined)
            {
                length = 10;
            }
            var str = "";
            for(var i = 0; i < length; i++)
            {
                str += this._getRandomChar();
            }
            return str;
        },
        _getRandomChar : function()
        {
            var index = Math.floor(Math.random() * this._legalCharList.length);
            return this._legalCharList[index];
        }
    };

    $.lvshuo = $.lvshuo || {};
    $.extend( $.lvshuo, {
        version : "0.6.3",
        defaultGradientBG : {
            "10" : "ui10GrayGradientBG",
            "20" : "ui20GrayGradientBG",
            "30" : "ui30GrayGradientBG",
            "40" : "ui40GrayGradientBG"
        },
        hoverGradientBG : {
            "10" : "ui10RoyalBlueGradientBG",
            "20" : "ui20RoyalBlueGradientBG",
            "30" : "ui30RoyalBlueGradientBG",
            "40" : "ui40RoyalBlueGradientBG"
        },
        selectedGradientBG : {
            "10" : "ui10BlueGradientBG",
            "20" : "ui20BlueGradientBG",
            "30" : "ui30BlueGradientBG",
            "40" : "ui40BlueGradientBG"
        },
        cssShow : { 
            position: "absolute", 
            visibility: "hidden",
            display: "block"
        },
        widgetOptionsDictionary : {},
        randomKey : new RandomString(),
        
        getWidgetOptions : function(key)
        {
            if(this.widgetOptionsDictionary[key] !== undefined)
            {
                return this.widgetOptionsDictionary[key];
            }
            return null;
        },
        
        addWidgetOptions : function(key, value)
        {
            this.widgetOptionsDictionary[key] =  value;
            return value;
        },
        
        removeWidgetOptions : function(key)
        {
            if(this.widgetOptionsDictionary[key] !== undefined)
            {
                var setting = this.widgetOptionsDictionary[key];
                this.widgetOptionsDictionary[key] = null;
                delete this.widgetOptionsDictionary[key];
                return setting;
            }
        },
        
        getRandomKey : function()
        {
            return  this.randomKey.getRandomStr();
        }
    });
})(jQuery);// JavaScript Document



;
(function($)
{
    $.lvshuo.draggable = $.lvshuo.draggable || {};
    var defaults = {
        dest : null,
        disable : false,
        
        start : false,
        clientX : 0,
        clientY : 0,
        doing : false,
        step : 2,
        type : "drag",
        mask : null,
        destPosition : null,
        HTML : '<div class="uiInteractionMask uiInactive uiCornerAll uiBlackBigBorder"></div>',
        firstCross : false,
        widget : null,
        
        event : {start : null, doing : null, stop : null},
        cross : null
    };
    $.fn.draggable = function(options)
    {
        var self = this;
        //if(typeof options == "string")
        if(options == "destroy")
        {
            var key = self.attr("widget");
            $(document).unbind("." + key);
            self.removeAttr("widget").find(".uiDraggalbe").unbind("mousedown");
            return self;
        }
        self.each( function()
        {
            var widgetKey = $(this).attr("widget");
            if(!widgetKey)
            {
                widgetKey = $.lvshuo.getRandomKey();
                $(this).attr("widget", widgetKey);
            }
            var opts =  $.extend({}, defaults, options);
            opts.widget = widgetKey;
            $.lvshuo.interaction.initInteraction.call($(this), opts);
        });
        return self;
    };
})(jQuery);// JavaScript Document


;
(function($)
{
    $.lvshuo.widget = $.lvshuo.widget || {};
    var $$ = $.extend($.lvshuo.widget, {
        
        initWidget : function()
        {
            var self = this, args = Array.prototype.slice.call(arguments), widgetSetting = args.pop(), options, opts, key;
            
            if(typeof args[0] == "string")
            {
                key = self.attr("widget"), widgetOptions = $$.widgetOptions(key);
                if(widgetOptions != null)
                {
                    if(self.length != 0)
                    {
                        self = $(self[0]);
                    }
                    self.opts = widgetOptions;
                    return $$.funcHandle.apply(self, args);
                }
            }
            
            else
            {
                if(self.attr("widget") !== undefined)
                {
                    return self;
                }
                if(args.length == 0)
                {
                    options = {};
                }
                else
                {
                    options = args[0];
                }
                self.each(function()
                {
                    var obj = $(this);                    
                    opts =  $.extend({}, widgetSetting.defaults, options);
                    opts.clone = obj.clone();
                    obj.opts = opts;
                    opts.widgetKey = $.lvshuo.getRandomKey();
                    obj.attr("widget",opts.widgetKey);
                    $$.widgetOptions(opts.widgetKey, opts);
                    var visibilityValue = $.style(obj[0], "visibility");
                    obj.css("visibility", "hidden");
                    widgetSetting.init.call(obj, opts);
                    $.style(obj[0], "visibility", visibilityValue);
                    
                });
            }
            return self;
        },
        
        option : function()
        {
            var self = this, opts = self.opts;
            if(opts[arguments[0]] === undefined)
            {
                return null;
            }
            if(arguments.length == 1)
            {
                return opts[arguments[0]];
            }
            else if(arguments.length > 1)
            {
                if(isNaN(arguments[1]))
                {
                    opts[arguments[0]] = arguments[1];
                }
                else
                {
                    opts[arguments[0]] = parseInt(arguments[1]);
                }
            }
            return self;
        },
        
        funcHandle : function()
        {
            var self = this, result = null, widget = $$.widget.call(self), param;
            if(!$.isFunction($.lvshuo[widget][arguments[0]]))
            {
                return result;
            }
            param = Array.prototype.slice.call(arguments,1);
            result = $.lvshuo[widget][arguments[0]].apply(self, param);
            return result;
        },
        
        widget : function()
        {
            var self = this;
            if(self.hasClass("uiDialog"))
            {
                return "dialog";
            }
            else if(self.hasClass("uiTabs"))
            {
                return "tabs";
            }
            else if(self.hasClass("uiSlide"))
            {
                return "slide";
            }
            else if(self.hasClass("uiAccordion"))
            {
                return "accordion";
            }
            else if(self.hasClass("uiButtonSet"))
            {
                return "buttonSet";
            }
            else if(self.hasClass("uiDorpDownList"))
            {
                return "dropDownList";
            }
            else if(self.hasClass("uiProgressBar"))
            {
                return "progressBar";
            }
            else if(self.hasClass("uiTip"))
            {
                return "tip";
            }
            else if(self.hasClass("uiList"))
            {
                return "list";
            }
            else if(self.hasClass("uiDatePicker"))
            {
                return "datePicker";
            }
            else
            {
                return "dialog";
            }
        },
        
        widgetOptions : function()
        {
            if(arguments.length == 2)
            {
                return $.lvshuo.addWidgetOptions(arguments[0], arguments[1]);
            }
            else if(arguments.length == 1)
            {
                return $.lvshuo.getWidgetOptions(arguments[0]);
            }
            return null;
        },
        
        removeWidgetOptions : function(key)
        {
            if( key !== undefined)
            {
                return $.lvshuo.removeWidgetOptions(key);
            }
            return null;
        },
        
        destroy : function(revert)
        {
            var self = this, opts = self.opts, widgetKey;
            if(!self.hasClass("uiWidget"))
            {
                self = opts.targetWidget;
            }
            if(self.hasClass("uiDraggalbe") || self.find(".uiDraggalbe").length != 0)
            {
                self.draggable("destroy");
            }
            if(self.find(".uiResizable").length != 0)
            {
                self.resizable("destroy");
            }
            $$.funcHandle.call(self, "beforeDestroy");
            self.removeClass("uiWidget").find(".uiWidget").each( function()
            {
                $$.removeWidgetOptions($(this).removeClass("uiWidget").attr("widget"));
            });
            widgetKey = self.attr("widget");
            $$.removeWidgetOptions(widgetKey);
            if(revert)
            {
                opts.clone.insertAfter(self);
            }
            opts.clone = null;
            opts = null;
            return self.remove();
        },
        
        disable : function()
        {
            var self = this, opts = self.opts;
            opts.disabled = true;
            return self.addClass("uiWidgetDisalbed");
        },
        
        enable : function()
        {
            var self = this, opts = self.opts;
            opts.disabled = false;
            return self.removeClass("uiWidgetDisalbed");
        }
    });
})(jQuery);// JavaScript Document


;
(function($)
{
    $.lvshuo.position = $.lvshuo.position || {};
    var defaults = {
        position : "center",
        oldPos : null,
        returnOldPos : false
    };
    
    $.fn.moveToPos = function(options)
    {
        var self = this, opts = options || {};
        opts =  $.extend({}, defaults, options);
        return $$.moveToPos.call(self, opts);
    };
    var $$ = $.extend($.lvshuo.position, {
        
        moveToPos : function(opts)
        {
            var self = this;
            var oldPos = {position : null, left : null, top : null, right : null, bottom : null};
            var returnValue;
            self.css("margin", 0);
            if(opts.returnOldPos)
            {
                $.each(oldPos, function(key)
                {
                    oldPos[key] = self.css(key);
                });
                returnValue = oldPos;
            }
            else
            {
                returnValue = self;
            }
            if(typeof opts.position == "string")
            {
                $$.setPosByStr.call(self, opts);
            }
            else if($.isArray(opts.position))
            {
                $$.setPosByArray.call(self, opts);
            }
            return returnValue;
        },
        
        setPosByStr : function(opts)
        {
            var self = this;
            var windowObj = $(window);
            var parentObj = self.parent();
            if(parentObj.attr("tagName").toUpperCase() == "BODY")
            {
                parentObj = windowObj;
            }
            var windowWidth = windowObj.width(), windowHeight = windowObj.height();
            var parentWidth = parentObj.width(), parentHeight = parentObj.height();
            var targetWidth = self.outerWidth(), targetHeight = self.outerHeight();
            var posSetting = {position: "absolute", left : null, top : null, right : null, bottom : null};
            var parentOffset = self.parent().offset();
            if(self.css("position") == "fixed")
            {
                posSetting.position = "fixed";
            }
            switch(opts.position)
            {
                case "center":
                    parentWidth = Math.max(Math.min(parentWidth, windowWidth), targetWidth);
                    parentHeight = Math.max(Math.min(parentHeight, windowHeight), targetHeight);
                    posSetting["left"] = parentOffset.left + (parentWidth - targetWidth) / 2;
                    posSetting["top"] = parentOffset.top + (parentHeight - targetHeight) / 2 + $(document).scrollTop();
                    break;
                case "leftBottom":
                    posSetting["left"] = posSetting["bottom"] = 0;
                    break;
                case "leftTop":
                    posSetting["left"] = posSetting["top"] = 0;
                    break;
                case "rightTop":
                    posSetting["right"] = posSetting["top"] = 0;
                    break;
                case "rightBottom":
                    posSetting["right"] = posSetting["bottom"] = 0;
                    break;
				case "prompt":
                    posSetting["left"] = parentOffset.left + (parentWidth - targetWidth) / 2;
					posSetting["top"] = (parentOffset.top + (parentHeight - targetHeight) / 2 + $(document).scrollTop())/2;
                    break;	
                default:
                    posSetting[opts.position] = 0;
                    break;
            }
            self.css(posSetting);
            return self;
        },
        
        setPosByArray : function(opts)
        {
            var self = this;
            var posSetting = {position: "absolute", left : opts.position[0], top : opts.position[1], right : null, bottom : null};
            if(self.css("position") == "fixed")
            {
                posSetting.position = "fixed";
            }
            self.css(posSetting);
            return self;
        }
    });
})(jQuery);// JavaScript Document



;
(function($)
{
    $.lvshuo.interaction = $.lvshuo.interaction || {};
    var $$ = $.extend($.lvshuo.interaction,  {
        
        initInteraction : function(options)
        {
            var self = this;
            var opts = options;
            if(opts.type == "resize")
            {
                var obj = self.find(".uiResizable");
                if(obj.length == 0)
                {
                    if(self.css("position") == "static")
                    {
                        self.css("position", "relative");
                    }
                    obj = $('<div class="uiResizable"></div>').appendTo(self);
                }
                obj.mousedown( function(e)
                {
                    $$.setInteractionMask(self, opts, e);
                });
            }
            else
            if(opts.type == "drag")
            {
                var obj = self.find(".uiDraggalbe");
                if(obj.length == 0)
                {
                    obj = self.addClass("uiDraggalbe");
                }
                obj.mousedown( function(e)
                {
                    $$.setInteractionMask(self, opts, e);
                });
            }
            var mouseMoveEvent = "mousemove." + opts.widget;
            var mouseUpEvent = "mouseup." + opts.widget;

            $(document).bind(mouseMoveEvent, function(e)
            {
                if(opts.start)
                {
                    opts.doing = true;
                    var offsetX = e.clientX - opts.clientX, offsetY = e.clientY - opts.clientY;
                    if(Math.abs(offsetX) < opts.step && Math.abs(offsetY) < opts.step)
                    {
                        return false;
                    }
                    var maskItem = opts.mask.show();
                    if(opts.type == "resize")
                    {
                        var newWidth = maskItem.width() + offsetX;
                        var newHeight = maskItem.height() + offsetY;
                        if(opts.maxWidth != null)
                        {
                            newWidth = Math.min(newWidth, opts.maxWidth);
                        }
                        else
                        if(opts.minWidth != null)
                        {
                            newWidth = Math.max(newWidth, opts.minWidth);
                        }
                        opts.clientX = e.clientX;

                        if(opts.maxHeight != null)
                        {
                            newHeight = Math.min(newHeight, opts.maxHeight);
                        }
                        else
                        if(opts.minHeight != null)
                        {
                            newHeight = Math.max(newHeight, opts.minHeight);
                        }
                        opts.clientY = e.clientY;
                        if($.isFunction(opts.event.doing))
                        {
                            if(opts.event.doing.call(self, newWidth, newHeight) == false)
                            {
                                return ;
                            }
                        }
                        maskItem.width(newWidth).height(newHeight);
                    }
                    else
                    if(opts.type = "drag")
                    {
                        opts.clientX = e.clientX;
                        opts.clientY = e.clientY;
                        var originOffset = maskItem.offset();
                        if($.isFunction(opts.event.doing))
                        {
                            if(opts.event.doing.call(self, {left : originOffset.left + offsetX, top : originOffset.top + offsetY}) == false)
                            {
                                return ;
                            }
                        }
                        maskItem.moveToPos({position : [originOffset.left + offsetX, originOffset.top + offsetY]});
                        if(opts.dest != null)
                        {
                            if($$.checkArea(maskItem, opts.destPosition) === true)
                            {
                                if(!opts.firstCross)
                                {
                                    opts.cross.call(self, true);
                                    opts.firstCross = true;
                                }
                            }
                            else
                            {
                                if(opts.firstCross)
                                {
                                    opts.cross.call(self, false);
                                    opts.firstCross = false;
                                }
                            }
                        }
                    }
                    return false;
                }
            })
            .bind(mouseUpEvent, function()
            {
                if(opts.mask === null)
                {
                    return ;
                }
                var maskItem = opts.mask;
                if(opts.doing)
                {
                    maskItem.show();
                    if($.isFunction(opts.event.stop))
                    {
                        if(opts.type == "resize")
                        {
                            opts.event.stop.call(self, maskItem.width(), maskItem.height());
                        }
                        else
                        if(opts.type == "drag")
                        {
                            var originOffset = maskItem.offset();
                            opts.event.stop.call(self, originOffset);
                        }
                    }
                }
                opts.start = false;
                opts.doing = false;
                maskItem.remove();
                opts.mask = null;
            });
            return self;
        },
        
        setInteractionMask : function(self, opts, e)
        {
            if(opts.disable)
            {
                return ;
            }
            if($.isFunction(opts.event.start))
            {
                if(opts.event.start.call(self) === false)
                {
                    return false;
                }
            }
            if($(e.target).hasClass("uiUserBtn"))
            {
                return true;
            }
            opts.start = true;
            opts.clientX = e.clientX;
            opts.clientY = e.clientY;
            var maskHeight = self.outerHeight(), maskWidth = self.outerWidth(), maskPosition = self.offset();
            opts.mask = $(opts.HTML).width(maskWidth).height(maskHeight).css({left : maskPosition.left, top : maskPosition.top}).hide().addClass("uiBlackBigBorder uiCornerAll").appendTo("body");
            if(opts.type == "drag" && opts.dest != null)
            {
                var dest = $(opts.dest);
                var pos = dest.offset();
                var destWidth = dest.width();
                var destHeight = dest.height();
                opts.destPosition = { leftTop : [pos.left, pos.top], rightBottom : [pos.left + destWidth, pos.top + destHeight]};
            }
            return self;
        },
        checkArea : function(obj, destPosition)
        {
            var left = obj.offset().left;
            var top = obj.offset().top;
            var right = left + obj.outerWidth();
            var bottom = top + obj.outerHeight();
            if((left > destPosition.rightBottom[0] | right < destPosition.leftTop[0]) | (bottom < destPosition.leftTop[1] | top > destPosition.rightBottom[1]))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    });
})(jQuery);// JavaScript Document



;
(function($)
{
    $.lvshuo.resizable = $.lvshuo.resizable || {};
    var defaults = {
        minWidth : null,
        minHeight : null,
        maxWidth : null,
        maxHeight : null,

        
        start : false,
        clientX : 0,
        clientY : 0,
        doing : false,
        step : 2,
        type : "resize",
        mask : null,
        disable : false,
        HTML : '<div class="uiInteractionMask uiInactive uiCornerAll uiBlackBigBorder"></div>',
        
        event : {start : null, doing : null, stop : null}
    };
    $.fn.resizable = function(options)
    {
        var self = this;
        //if(typeof options == "string")
        if(options == "destroy")
        {
            var key = self.attr("widget");
            $(document).unbind("." + key);
            self.removeAttr("widget").find(".uiResizable").unbind("mousedown").remove();
            return self;
        }
        self.each( function()
        {
            var widgetKey = $(this).attr("widget");
            if(!widgetKey)
            {
                widgetKey = $.lvshuo.getRandomKey();
                $(this).attr("widget", widgetKey);
            }
            var opts =  $.extend({}, defaults, options);
            opts.widget = widgetKey;
            $.lvshuo.interaction.initInteraction.call($(this), opts);
        });
        return self;
    };
})(jQuery);// JavaScript Document



;
(function($)
{
    $.lvshuo.buttonSet = $.lvshuo.buttonSet || {};
    $.lvshuo.buttonSet.defaults = {
        
        btnSetClass: "uiCornerAll uiGrayBoxShadow",
        btnClass : $.lvshuo.defaultGradientBG["40"],
        btnSetBorderClass : "uiGrayBorder",
        btnHoverClass : "ui40LightBlueGradientBG",
        btnSelectedClass : $.lvshuo.selectedGradientBG["40"],
        btnPressClass : "ui40CadetBlueGradientBG",
        btnWidth : null,
        btnMargin : null,
        
        iconArray : null,
        iconFloatArray : null,
        disabled : false,
        defaultSelectedItem : null,
        
        vertical : false,
        
        
        widgetKey : null,
        statusClass : null,
        imgIconHTML : '<div class="uiIcon"></div>',
        
        
        click : null
    };

    
    $.fn.buttonSet = function()
    {
        var self = this;
        var args = Array.prototype.slice.call(arguments);
        var widgetSetting = {defaults : $.lvshuo.buttonSet.defaults, init : $$.init};
        args.push(widgetSetting);
        return $$.initWidget.apply(self, args);
    };
    var $$ = $.extend($.lvshuo.buttonSet, $.lvshuo.widget, {
        
        init : function(opts)
        {
            var self = this;
            
            //self.addClass("uiButtonSet uiWidget uiNoSelectText " + opts.btnSetClass + " " + opts.btnSetBorderClass).children().each(function(n)
            opts.btnSelectedClass += " uiActive";
            opts.statusClass = {};
            self.addClass("uiButtonSet uiWidget uiNoSelectText").children().each( function(n)
            {
                var obj = $(this), btnClass;
                if(opts.btnMargin)
                {
                    btnClass = "uiButton uiCornerAll " + opts.btnClass + " " + opts.btnSetBorderClass;
                }
                else
                {
                    btnClass = "uiButton " + opts.btnClass;
                }
                
                if(obj.hasClass("uiImgRadio") || obj.hasClass("uiImgCheckBox"))
                {
                    obj.prepend(opts.imgIconHTML);
                }
                if(n != 0)
                {
                    if(opts.btnMargin)
                    {
                        if(opts.vertical)
                        {
                            obj.css("margin-top", opts.btnMargin);
                        }
                        else
                        {
                            obj.css("margin-left", opts.btnMargin);
                        }
                    }
                    else
                    {
                        if(opts.vertical)
                        {
                            btnClass += (" uiBorderTop " + opts.btnSetBorderClass);
                        }
                        else
                        {
                            btnClass += (" uiBorderLeft " + opts.btnSetBorderClass);
                        }
                    }
                }
                obj.addClass(btnClass);
                if($.isArray(opts.iconArray))
                {
                    var index = n;
                    var floatClass = "";
                    if(index >= opts.iconArray.length)
                    {
                        index =  opts.iconArray.length - 1;
                    }
                    if($.isArray(opts.iconFloatArray))
                    {
                        if(n >= opts.iconFloatArray.length)
                        {
                            floatClass = opts.iconFloatArray[opts.iconFloatArray.length - 1];
                        }
                        else
                        {
                            floatClass = opts.iconFloatArray[n];
                        }
                        if(floatClass == "right")
                        {
                            floatClass = "uiIconFloatRight";
                        }
                    }
                    obj.prepend('<span class="uiIcon ' + opts.iconArray[index] +  " " + floatClass + '"></span>');
                }
                if(opts.btnWidth)
                {
                    obj.width(opts.btnWidth);
                }
            });
            if(opts.btnMargin == null)
            {
                self.addClass(opts.btnSetClass + " " + opts.btnSetBorderClass);
            }
            if(opts.vertical)
            {
                self.width(self.children().outerWidth(true));
            }
            
            $$.initEvent.call(self);
            if(opts.disabled)
            {
                $$.disable.call(self);
            }
            if(opts.defaultSelectedItem != null)
            {
                $$.changeButtonStatus.call(self.children().eq(opts.defaultSelectedItem), opts);
            }
            return self;
        },
        
        initEvent : function()
        {
            var self = this, opts = self.opts, mouseDownFlag = false;
            self.children(".uiButton, .uiImgButton").bind("mouseenter.uiButtonSet mouseleave.uiButtonSet mousedown.uiButtonSet mouseup.uiButtonSet click.uiButtonSet", function(e)
            {
                if(opts.disabled)
                {
                    return false;
                }
                if(e.type === "click")
                {
                    if($.isFunction(opts.click))
                    {
                        if(opts.click.call(this, e) === false)
                        {
                            return false;
                        }
                    }
                    $$.changeButtonStatus.call(this, opts);
                    return ;
                }
                var classValue;
                var funcValue ;
                switch(e.type)
                {
                    case "mouseenter":
                        classValue = opts.btnHoverClass;
                        funcValue = "setStatusClass";
                        break;
                    case "mouseleave":
                        classValue = opts.btnHoverClass;
                        funcValue = "removeStatusClass";
                        break;
                    case "mousedown":
                        classValue = opts.btnPressClass;
                        funcValue = "setStatusClass";
                        break;
                    case "mouseup":
                        classValue = opts.btnPressClass;
                        funcValue = "removeStatusClass";
                        break;
                }
                $$[funcValue].call(this, opts, classValue);
            });
            return self;
        },
        changeButtonStatus : function(opts)
        {
            var obj = $(this), group;
            if(obj.hasClass("uiRadio") || obj.hasClass("uiImgRadio"))
            {
                group = obj.attr("group");
                var siblingsObj = obj.siblings('[group="' +group + '"]');
                obj.removeClass(opts.btnHoverClass + " " + opts.btnClass).addClass(opts.btnSelectedClass);
                siblingsObj.removeClass(opts.btnSelectedClass).addClass(opts.btnClass);
                if(obj.hasClass("uiImgRadio"))
                {
                    obj.addClass("uiImgRadioChecked");
                    siblingsObj.removeClass("uiImgRadioChecked");
                }
            }
            else if(obj.hasClass("uiCheckBox") || obj.hasClass("uiImgCheckBox"))
            {
                if(opts.statusClass[opts.btnHoverClass] == null)
                {
                    obj.toggleClass(opts.btnSelectedClass).toggleClass(opts.btnClass);
                }
                else if(opts.statusClass[opts.btnHoverClass] != opts.btnSelectedClass)
                {
                    obj.removeClass(opts.btnHoverClass).addClass(opts.btnSelectedClass);
                }
                else
                {
                    obj.removeClass(opts.btnHoverClass).addClass(opts.btnClass);
                }
                if(obj.hasClass("uiImgCheckBox"))
                {
                    obj.toggleClass("uiImgCheckBoxChecked");
                }
            }
            else
            {
                obj.removeClass(opts.btnHoverClass).addClass(opts.btnClass);
            }
            $.each(opts.statusClass, function(key, value)
            {
                opts.statusClass[key] = null;
            });
        },
        setOriginClass : function(opts, statusClass)
        {
            var obj = $(this);
            $.each([opts.btnClass, opts.btnSelectedClass, opts.btnHoverClass, opts.btnPressClass], function(n, value)
            {
                if(obj.hasClass(value))
                {
                    opts.statusClass[statusClass] = value;
                }
                obj.removeClass(value);
            });
        },
        getOriginClass : function(opts, statusClass)
        {
            if(opts.statusClass[statusClass] == null)
            {
                return ;
            }
            var obj = $(this);
            $.each([opts.btnClass, opts.btnSelectedClass, opts.btnHoverClass, opts.btnPressClass], function(n, value)
            {
                obj.removeClass(value);
            });
            obj.addClass(opts.statusClass[statusClass]);
        },
        setStatusClass : function(opts, statusClass)
        {
            $$.setOriginClass.call(this, opts, statusClass);
            $(this).addClass(statusClass);
        },
        removeStatusClass : function(opts, statusClass)
        {
            $$.getOriginClass.call(this, opts, statusClass);
        },     
        clickButton : function(index)
        {
            var self = this, opts = self.opts;
            if(index === undefined)
            {
                return $();
            }
            var obj = self.children().eq(index).trigger("click.uiButtonSet");
            return self;
        },
        button : function(index)
        {
            var self = this, opts = self.opts;
            if(index === undefined)
            {
                return $();
            }
            return self.children().eq(index);
        },
        buttonText : function(index, text)
        {
            var self = this, opts = self.opts;
            if(index === undefined)
            {
                return $();
            }
            var obj = self.children().eq(index);
            if(typeof text == "undefined")
            {
                return obj.text();
            }
            obj.html(obj.html().replace(obj.text(), text));
            return self;
        },
        buttonIcon : function(index, icon)
        {
            var self = this, opts = self.opts;
            if(index === undefined || !$.isArray(opts.iconArray))
            {
                return $();
            }
            var obj = self.children().eq(index);
            var arrayIndex = opts.iconArray.length - 1;            
            var iconClass;
            if(index > arrayIndex)
            {
                index = arrayIndex;
            }
            iconClass = opts.iconArray[index];
            if(typeof icon == "undefined")
            {
                return iconClass;
            }
            obj.children("span").removeClass(iconClass).addClass(icon);
            opts.iconArray[index] = icon;
            return self;
        },
        val : function(index, checked)
        {
            var self = this, opts = self.opts;
            if(index === undefined)
            {
                return ;
            }
            var obj = self.children().eq(index);
            var hasStatus = false;
            $.each("uiCheckBox uiRadio uiImgRadio uiImgCheckBox".split(" "), function(n, value)
            {
               if(obj.hasClass(value))
               {
                   hasStatus = true;
                   return false;
               } 
            });
            if(!hasStatus)
            {
                return ;
            }
            if(checked === undefined)
            {
                if(obj.hasClass(opts.btnSelectedClass))
                {
                    return true;
                }
                return false;
            }
            if(checked)
            {
                if(!obj.hasClass(opts.btnSelectedClass))
                {
                    obj.trigger("click.uiButtonSet");
                }
            }
            else
            {
                if(obj.hasClass(opts.btnSelectedClass))
                {
                    obj.removeClass(opts.btnSelectedClass).addClass(opts.btnClass);
                }                
            }
            return self;
        },
        removeButton : function(index)
        {
            var self = this, opts = self.opts;
            if(index === undefined)
            {
                return self;
            }
            return self.children(".uiButton").eq(index).remove();
        }
    });
})(jQuery);// JavaScript Document



;
(function($)
{
    $.lvshuo.dialog = $.lvshuo.dialog || {};

    $.lvshuo.dialog.defaults = {
        
        dlgClass : "uiBlueBigBorder uiCornerAll uiBlueBoxShadow",
        titleBarClass : $.lvshuo.selectedGradientBG["40"],
        
        position : null,
        
        zIndex : 1000,
        
        draggable : false,
        
        resizable : false,
        
        minStatusWidth : 250,
        
        modal : false,
        
        buttonSet : null,
        
        minHeight : 300,
        maxHeight : 700,
        
        minWidth : 400,
        maxWidth : 1000,
        
        //closeOnEscape : false,
        active : true,
        minimize : true,
        closable : true,
        noTitle : false,
        titleIcon : null,
        
        controlButton : true,
        disabled : false,
        autoOpen : true,
        destroyOnClose : true,
        closeAnimate : "slideUp",
        openAnimate : "slideDown",
        
        
        widgetKey : null,
        
        dlgMinHeight : 0,
        
        dlgHeight : 0,
        
        dlgWidth : 0,
        
        dlgPosition : null,
        overflowStatus : null,
        controlButtonSetHTML : '<div class="uiDlgButtonSet"><div class="uiUserBtn uiMinBtn"></div><div class="uiUserBtn uiCloseBtn"></div></div>',
        titleBarHTML : '<div class="uiTitleBar"><span class="uiTitle"></span></div>',
        contentHTML : '<div class="uiContent"></div>',
        resizeHTML :'<div class="uiResizable"></div>',
        selectList : null,
        
        
        
        beforeClose : null,
        close : null,
        beforeOpen : null,
        open : null,
        
        beforeMin : null,
        min : null,
        
        beforeResume : null,
        resume : null,
        dragStart : null,
        draging : null,
        dragStop : null,
        resizeStart : null,
        resizing : null,
        resizeStop : null
    };

    
    $.fn.dialog = function()
    {
        var self = this;
        var args = Array.prototype.slice.call(arguments);
        var widgetSetting = {defaults : $.lvshuo.dialog.defaults, init : $$.init};
        args.push(widgetSetting);
        return $$.initWidget.apply(self, args);
    };
    var $$ = $.extend($.lvshuo.dialog, $.lvshuo.widget, {
        
        init : function(opts)
        {
            var self = this, titleBarClass = opts.titleBarClass + " uiCornerAll";

            opts.title = self.attr("title");
            opts.content = $.trim(self.html());
            
            if(opts.draggable)
            {
                titleBarClass += (" uiDraggalbe");
            }
            
            var controlButton = null;
            if(opts.controlButton)
            {
                controlButton = $(opts.controlButtonSetHTML);
                if(!opts.minimize)
                {
                    controlButton.children(".uiMinBtn").hide();
                }
                if(!opts.closable)
                {
                    controlButton.children(".uiCloseBtn").hide();
                }
            }

            

            var content =self.children().addClass("uiContent");
            if(opts.noTitle)
            {
                self.addClass("uiDialog uiWidget " + opts.dlgClass);
            }
            else
            {
                var tileBar = $(opts.titleBarHTML).addClass(titleBarClass).append(controlButton).children(".uiTitle").html(opts.title).end();
                if(opts.titleIcon != null)
                {
                    tileBar.children(".uiTitle").prepend($('<span class="uiTitleIcon" />').addClass(opts.titleIcon));
                }
                self.addClass("uiDialog uiWidget " + opts.dlgClass).prepend(tileBar);
            }
            
            if(opts.position !== null)
            {
                self.css("z-index", opts.zIndex + 1).moveToPos({position : opts.position});
            }
            
            if(opts.modal)
            {
                var maskObj = $("<div />").addClass("uiMask").appendTo("body");
                if($.browser.msie && $.browser.version == "6.0")
                {
                    opts.selectList = $("select:visible").filter(function(i)
                    {
                        if($(this).css("visibility") != "hidden")
                        {
                            return true;
                        }
                        return false;
                    }).css("visibility", "hidden");
                    maskObj.height($(document).height());
                }
            }
            
            if(opts.buttonSet != null)
            {
                var buttonSetHTML = "<div>";
                for(var key in opts.buttonSet)
                {
                    buttonSetHTML += ("<div>" + key + "</div>");
                }
                buttonSetHTML += "</div>";
                $(buttonSetHTML).buttonSet({
                    click : function()
                    {
                        if(opts.disabled)
                        {
                            return false;
                        }
                        if(opts.buttonSet[$(this).html()].call(this) === false)
                        {
                            return false;
                        }
                        $$.close.call(self);
                    }
                }).appendTo(self);
            }
            
            if(opts.resizable)
            {
                self.append(opts.resizeHTML);
                if(self.css("position") == "static")
                {
                    self.css("position", "relative");
                }
            }
            opts.minHeight = Math.min(self.height(), opts.minHeight);
            opts.minWidth = Math.min(self.width(), opts.minWidth);
            $$.setContentHeight.call(self);
            
            $$.initEvent.call(self);
            if(opts.disabled)
            {
                $$.disable.call(self);
            }
            if(!opts.autoOpen)
            {
                self.hide();
            }
            return self;
        },
        initEvent : function()
        {
            var self = this, opts = self.opts, posStr = self.css("position");
            
            self.find("> .uiTitleBar > .uiDlgButtonSet > .uiUserBtn").bind("click.uiDialog", function(e)
            {
                if(opts.disabled)
                {
                    return false;
                }
                var obj = $(this);
                if(obj.hasClass("uiMinBtn"))
                {
                    if($.isFunction(opts.beforeMin))
                    {
                        if(opts.beforeMin.call(this, e) === false)
                        {
                            return false;
                        }
                    }
                    $$.min.call(self, e);
                }
                else if(obj.hasClass("uiResumeBtn"))
                {
                    if($.isFunction(opts.beforeResume))
                    {
                        if(opts.beforeResume.call(this, e) === false)
                        {
                            return false;
                        }
                    }
                    $$.resume.call(self, e);
                }
                else if(obj.hasClass("uiCloseBtn"))
                {
                    if($.isFunction(opts.beforeClose))
                    {
                        if(opts.beforeClose.call(this, e) === false)
                        {
                            return false;
                        }
                    }
                    $$.close.call(self, e);
                }
            });
            
            if(opts.draggable)
            {
                var dragStopFunc = function(offset)
                {
                    if(opts.disabled)
                    {
                        return false;
                    }
                    if($.isFunction(opts.dragStop))
                    {
                        if(opts.dragStop.call(self) === false)
                        {
                            return false;
                        }
                    }
                    self.moveToPos({position : [offset.left, offset.top]});
                };

                self.draggable({
                    event : {start : opts.dragStart, doing : opts.draging,  stop : dragStopFunc}
                });
            }
            
            if(opts.resizable)
            {
                var resizeStopFunc = function(width, height)
                {
                    if(opts.disabled)
                    {
                        return false;
                    }
                    if($.isFunction(opts.resizeStop))
                    {
                        if(opts.resizeStop.call(self) === false)
                        {
                            return false;
                        }
                    }
                    height = Math.min(Math.max(opts.minHeight, height), opts.maxHeight);
                    width = Math.min(Math.max(opts.minWidth,  width), opts.maxWidth);
                    var otherItemHeightTotal = 0, content = self.width(width).height(height).children(".uiContent");
                    self.children().each( function()
                    {
                        var obj = $(this);
                        if(!obj.hasClass("uiContent") && !obj.hasClass("uiResizable"))
                        {
                            otherItemHeightTotal += $(this).outerHeight(true);
                        }
                    });
                    var outerOffset = content.outerHeight(true) - content.height();
                    content.height(height - otherItemHeightTotal - outerOffset);
                };

                self.resizable({
                    event : {start : opts.resizeStart, doing : opts.resizing,  stop : resizeStopFunc},
                    minHeight : opts.minHeight,
                    maxHeight : opts.maxHeight,
                    minWidth : opts.minWidth,
                    maxWidth : opts.maxWidth
                });
            }
            
            
            if(posStr != "static" && posStr != "relative")
            {
                if(opts.active && opts.autoOpen)
                {
                    $(".uiDialog").not(self).each( function()
                    {
                        var obj = $(this);
                        if(obj.css("position") != "static" && obj.css("position") != "relative")
                        {
                            obj.css("z-index", opts.zIndex).children(".uiTitleBar").addClass("uiInactive");
                        }
                    });
                }
                self.bind("mousedown.uiDialog", function(e)
                {
                    if(opts.disabled)
                    {
                        return ;
                    }
                    self.css("z-index", opts.zIndex + 1).children(".uiTitleBar").removeClass("uiInactive");
                    self.siblings(".uiDialog").each( function()
                    {
                        var obj = $(this);
                        if(obj.css("position") != "static" && obj.css("position") != "relative")
                        {
                            obj.css("z-index", opts.zIndex).children(".uiTitleBar").addClass("uiInactive");
                        }
                    });
                    var target = $(e.target);
                    if(target.hasClass("uiDraggalbe") || target.hasClass("uiResizable") || target.parent().hasClass("uiDraggalbe"))
                    {
                        return false;
                    }
                });
            }
            return self;
        },
        
        min : function(e)
        {
            var self = this, opts = self.opts;
            $(">.uiTitleBar >.uiDlgButtonSet >.uiMinBtn", self).removeClass("uiMinBtn").addClass("uiResumeBtn");
            opts.dlgMinHeight = self.find("> .uiTitleBar").outerHeight(true);
            opts.dlgHeight = self.height();
            opts.dlgWidth = self.width();
            if(opts.resizable)
            {
                $(".uiResizable", self).hide();
            }
            var positionStr = self.css("position");
            if(positionStr === "static" || positionStr === "relative")
            {
                opts.overflowStatus = self.css("overflow");
                self.height(opts.dlgMinHeight).css("overflow", "hidden");
            }
            else
            {
                var oldPos = {position : null, left : null, top : null, right : null, bottom : null};
                $.each(oldPos, function(key)
                {
                    oldPos[key] = self.css(key);
                });
                if(positionStr == "absolute")
                {
                    oldPos["top"] = parseInt(oldPos["top"]) - $(document).scrollTop();
                }
                opts.dlgPosition = oldPos;
                positionStr = "fixed";
                
                if($.browser.msie && $.browser.version == "6.0")
                {
                    positionStr = "absolute";
                }
                self.css({right : null, bottom : null, position : positionStr}).animate({height : opts.dlgMinHeight, width : opts.minStatusWidth, left : 0, top : 0}, 300);
                //self.height(opts.dlgMinHeight).width(opts.minStatusWidth).css({left : 0, top : 0, right : null, bottom : null, position : positionStr});
            }
            if($.isFunction(opts.min))
            {
                if(opts.min.call(self[0], e) === false)
                {
                    return false;
                }
            }
            return self;
        },
        
        resume : function(e)
        {
            var self = this, opts = self.opts;
            $(">.uiTitleBar >.uiDlgButtonSet >.uiResumeBtn", self).removeClass("uiResumeBtn").addClass("uiMinBtn");
            if(opts.resizable)
            {
                $(".uiResizable", self).show();
            }
            var position = self.css("position");
            if(position === "static")
            {
                self.height(opts.dlgHeight).width(opts.dlgWidth).css("overflow", opts.overflowStatus);
            }
            else
            {
                if(opts.dlgPosition["position"] == "absolute")
                {
                    opts.dlgPosition["top"] = parseInt(opts.dlgPosition["top"]) + $(document).scrollTop();
                }
                var tmpSetting = $.extend({}, opts.dlgPosition, {height : opts.dlgHeight, width : opts.dlgWidth});
                //self.height(opts.dlgHeight).width(opts.dlgWidth).css(opts.dlgPosition);
                self.css(tmpSetting);
            }
            if($.isFunction(opts.resume))
            {
                if(opts.resume.call(self[0], e) === false)
                {
                    return false;
                }
            }
            return self;
        },
        
        close : function(e)
        {
            var self = this, opts = self.opts;
            if(opts.modal)
            {
                if($.browser.msie && $.browser.version == "6.0")
                {
                    opts.selectList.css("visibility", "visible");
                }
                $(".uiMask").remove();
            }
            self[opts.closeAnimate]( function()
            {
                if($.isFunction(opts.close))
                {
                    if(opts.close.call(this, e) === false)
                    {
                        return false;
                    }
                }
                if(opts.destroyOnClose)
                {
                    $$.destroy.call(self);
                }
            });
            return self;
        },
        open : function()
        {
            var self = this, opts = self.opts;
            if(self.css("position") != "static")
            {
                if(opts.active)
                {
                    self.siblings(".uiDialog").each( function()
                    {
                        var obj = $(this);
                        if(obj.css("position") != "static")
                        {
                            obj.css("z-index", opts.zIndex).children(".uiTitleBar").addClass("uiInactive");
                        }
                    });
                }
            }
            if($.isFunction(opts.beforeOpen))
            {
                if(opts.beforeOpen.call(self) === false)
                {
                    return self;
                }
            }
            
            if(opts.modal)
            {
                if($(".uiMask").length == 0)
                {
                    $("<div />").addClass("uiMask").appendTo("body");
                }
            }
            self[opts.openAnimate]( function()
            {
                if($.isFunction(opts.open))
                {
                    opts.open.call(self);
                }
            });
            return self;
        },
        
        title : function(title)
        {
            var self = this, opts = self.opts;
            var obj = $("> .uiTitleBar > .uiTitle", self);
            if(title === undefined)
            {
                return obj.text();
            }
            obj.html(obj.html().replace(obj.text(), title));            
            return self.attr("title", title);
        },
        
        titleIcon : function(titleIcon)
        {
            var self = this, opts = self.opts;
            if(titleIcon === undefined)
            {
                return opts.titleIcon;
            }
            if(opts.titleIcon == null)
            {
                $("> .uiTitleBar > .uiTitle", self).prepend('<span class="uiTitleIcon" />');
            }
            var obj = $("> .uiTitleBar > .uiTitle > .uiTitleIcon", self).removeClass(opts.titleIcon).addClass(titleIcon);
            opts.titleIcon = titleIcon;
            return self;
        },
        setContentHeight : function()
        {
            var self = this, opts = self.opts;
            var otherItemHeightTotal = 0, contentHeight = 0, outerOffset = 0, content = self.children(".uiContent");
            self.children().each( function()
            {
                var obj = $(this);
                if(!obj.hasClass("uiContent") && !obj.hasClass("uiResizable"))
                {
                    otherItemHeightTotal += $(this).outerHeight(true);
                }
            });  
            contentHeight = content.outerHeight(true);
            outerOffset = contentHeight - content.height();    
            var imgList = self.find("img");
            if(imgList.length != 0)
            {
                var imgTotal = imgList.length;
                var completeLoad = 0;
                imgList.each(function()
                {
                    if(this.complete)
                    {
                        completeLoad++;
                        if(completeLoad == imgTotal) 
                        {
                            content.height(self.height() - otherItemHeightTotal - outerOffset);
                        }
                    }
                    else
                    {
                        $(this).load(function()
                        {
                            completeLoad++;
                            if(completeLoad == imgTotal)
                            {
                                content.height(self.height() - otherItemHeightTotal - outerOffset);
                            }
                        });
                    }
                });
            }  
            else
            {
                content.height(self.height() - otherItemHeightTotal - outerOffset);
            }
        }
    });
})(jQuery);